package com.zhrd.bussinss.platform.controller;


import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zhrd.bussinss.platform.bo.UserApplyInfo;
import com.zhrd.bussinss.platform.service.BbtangHomeService;

import net.sf.json.JSONObject;

@Controller
@RequestMapping("/")
public class BbtangHomeController {
	
	private static final String INDEX = "index";
	private static final String DOWNLOAD = "downLoad";
	private static final String ABOUT = "about";
	private static final String CONTACT = "contact";
	
	@Autowired
	BbtangHomeService bbtangHomeService;
	
	@RequestMapping(value = "/index", method = RequestMethod.GET)
	public String init(HttpServletRequest request,HttpServletResponse response) {
		
		return INDEX;
	}
	@RequestMapping(value = "/downLoad", method = RequestMethod.GET)
	public String downLoad(HttpServletRequest request,HttpServletResponse response) {
		
		return DOWNLOAD;
	}
	@RequestMapping(value = "/about", method = RequestMethod.GET)
	public String about(HttpServletRequest request,HttpServletResponse response) {
		
		return ABOUT;
	}
	@RequestMapping(value = "/contact", method = RequestMethod.GET)
	public String contact(HttpServletRequest request,HttpServletResponse response) {
		
		return CONTACT;
	}
	
	@RequestMapping(value = "/apply", method = RequestMethod.POST)
	@ResponseBody
	public String apply(HttpServletRequest request,HttpServletResponse response) {
		JSONObject result = new JSONObject();
		try {
		String username = request.getParameter("username");
		String major = request.getParameter("major");
		String contact = request.getParameter("contact");
		String school = request.getParameter("school");
		String info = request.getParameter("info");
		UserApplyInfo UserApplyInfo  = new UserApplyInfo();
		UserApplyInfo.setContact(contact);
		UserApplyInfo.setCreatetime(new Date());
		UserApplyInfo.setInfo(info);
		UserApplyInfo.setMajor(major);
		UserApplyInfo.setSchool(school);
		UserApplyInfo.setUsername(username);
		
		bbtangHomeService.save(UserApplyInfo);
			
		} catch (Exception e) {
//			e.printStackTrace();
			return "error";
		}
		
		return "success";
	}
	
}
